package com.cy.jmh;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.concurrent.TimeUnit;

public class JMHDemo1 {

	// @Benchmark
	// @BenchmarkMode(Mode.AverageTime)
	// @Warmup(iterations = 1, time = 1)
	// // 这里的意思是跑5轮 以这个方法举例 实际让是 1轮为1秒 那么 1轮大概率是跑100次  5轮就是500次
	// @Measurement(iterations = 3, time = 1)
	// @OutputTimeUnit(TimeUnit.MILLISECONDS)
	// public void test_AverageTime() throws InterruptedException {
	// 	TimeUnit.MILLISECONDS.sleep(10);
	// }


	// @Benchmark
	// @BenchmarkMode(Mode.Throughput)
	// @Warmup(iterations = 1, time = 1)
	// @Measurement(iterations = 3, time = 1)
	// @OutputTimeUnit(TimeUnit.SECONDS)
	// public void test_Throughput() throws InterruptedException {
	// 	TimeUnit.MILLISECONDS.sleep(10);
	// }


	// @Benchmark
	// @BenchmarkMode(Mode.SampleTime)
	// @Warmup(iterations = 1, time = 1)
	// @Measurement(iterations = 3, time = 1)
	// @OutputTimeUnit(TimeUnit.MILLISECONDS)
	// public void test_SampleTime() throws InterruptedException {
	// 	TimeUnit.MILLISECONDS.sleep(10);
	// }

	@Benchmark
	@BenchmarkMode(Mode.SingleShotTime)
	@Warmup(iterations = 1, time = 1)
	@Measurement(iterations = 3, time = 1)
	@OutputTimeUnit(TimeUnit.MILLISECONDS)
	public void test_SingleShotTime() throws InterruptedException {
		TimeUnit.MILLISECONDS.sleep(10);
	}


	public static void main(String[] args) throws RunnerException {
		Options opt = new OptionsBuilder()
				.include(JMHDemo1.class.getSimpleName())
				.forks(1)
				.build();
		new Runner(opt).run();
	}
}
